package com.weyoung.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weyoung.app.mapper.HealthDataMapper;
import com.weyoung.app.pojo.dto.CaloriesDTO;
import com.weyoung.app.pojo.dto.StepsDTO;
import com.weyoung.app.pojo.dto.HeartDTO;
import com.weyoung.app.pojo.entity.HealthData;
import com.weyoung.app.pojo.entity.Series;
import com.weyoung.app.service.HealthDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 健康数据实体的 Service 实现类，继承自 ServiceImpl 并实现 HealthDataService 接口
 */
@Service
public class HealthDataServiceImpl extends ServiceImpl<HealthDataMapper, HealthData> implements HealthDataService {

    @Autowired
    HealthDataMapper healthDataMapper;


    @Override
    public CaloriesDTO getCaloriesDay() {
        CaloriesDTO caloriesDTO = healthDataMapper.getCaloriesDay();
        Series series = caloriesDTO.getSeries();
        series.setName("卡路里");

        caloriesDTO.setSeries(series);

        String[] timeSlots = {"08:00", "12:00", "16:00", "20:00"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        caloriesDTO.setCategories(sb.toString());
        return caloriesDTO;
    }

    @Override
    public CaloriesDTO getCaloriesWeekend() {
        CaloriesDTO caloriesDTO = healthDataMapper.getCaloriesWeekend();
        Series series = caloriesDTO.getSeries();
        series.setName("卡路里");

        caloriesDTO.setSeries(series);

        String[] timeSlots = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        caloriesDTO.setCategories(sb.toString());
        return caloriesDTO;
    }

    @Override
    public CaloriesDTO getCaloriesMonth() {
        CaloriesDTO caloriesDTO = healthDataMapper.getCaloriesMonth();
        Series series = caloriesDTO.getSeries();
        series.setName("卡路里");

        caloriesDTO.setSeries(series);

        String[] timeSlots = {"第1周", "第2周", "第3周", "第4周"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        caloriesDTO.setCategories(sb.toString());
        return caloriesDTO;
    }

    @Override
    public List<StepsDTO> getStepsDay() {
        return healthDataMapper.getStepsDay();
    }

    @Override
    public List<StepsDTO> getStepsWeekend() {
        return healthDataMapper.getStepsWeekend();
    }

    @Override
    public List<StepsDTO> getStepsMonth() {

        return healthDataMapper.getStepsMonth();
    }

    @Override
    public HeartDTO getHeartDay() {
        HeartDTO heartDTO = healthDataMapper.getHeartDay();

        String[] timeSlots = {"08:00", "12:00", "16:00", "20:00"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        heartDTO.setCategories(sb.toString());
        return heartDTO;
    }

    @Override
    public HeartDTO getHeartWeekend() {
        HeartDTO heartDTO = healthDataMapper.getHeartWeekend();

        String[] timeSlots = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        heartDTO.setCategories(sb.toString());
        return heartDTO;
    }

    @Override
    public HeartDTO getHeartMonth() {
        HeartDTO heartDTO = healthDataMapper.getHeartMonth();

        String[] timeSlots = {"第1周", "第2周", "第3周", "第4周"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        heartDTO.setCategories(sb.toString());
        return heartDTO;
    }

    @Override
    public HeartDTO getBloodDay() {
        HeartDTO heartDTO = healthDataMapper.getBloodDay();

        String[] timeSlots = {"08:00", "12:00", "16:00", "20:00"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        heartDTO.setCategories(sb.toString());
        return heartDTO;
    }

    @Override
    public HeartDTO getBloodWeekend() {
        HeartDTO heartDTO = healthDataMapper.getBloodWeekend();

        String[] timeSlots = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        heartDTO.setCategories(sb.toString());
        return heartDTO;
    }

    @Override
    public HeartDTO getBloodMonth() {
        HeartDTO heartDTO = healthDataMapper.getBloodMonth();

        String[] timeSlots = {"第1周", "第2周", "第3周", "第4周"};
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < timeSlots.length; i++) {
            if (i > 0) {
                sb.append(",");
            }
            sb.append(timeSlots[i]);
        }
        sb.append("]");

        heartDTO.setCategories(sb.toString());
        return heartDTO;
    }


}